/**
   DanmuTestServiceImpl
 * Time:2018年6月20日
 */
package com.ssm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssm.dao.TestdanmuMapper;
import com.ssm.entity.Page;
import com.ssm.entity.Testdanmu;
import com.ssm.entity.TestdanmuExample;
import com.ssm.entity.TestdanmuExample.Criteria;
import com.ssm.service.DanmuService;
import com.ssm.service.DanmuTestService;

/**
 * @author 15199
 *
 */
@Service("danmuTestService")
public class DanmuTestServiceImpl implements DanmuTestService {

	@Resource
	private TestdanmuMapper testdanmuMapper;
	@Override
	public int saveDanmu(Testdanmu dTestdanmu) {
		int n=0;
		if(dTestdanmu.getUserid()!=null&&dTestdanmu.getVideoid()!=null){
			n=testdanmuMapper.insert(dTestdanmu);  
		}
		return n;	
	}
	@Override
	public List<Testdanmu> showDanmu() {
	
		return testdanmuMapper.selectByExample(null);
	}
	@Override
	public List<Testdanmu> list(Page page, Testdanmu testdanmu) {
		TestdanmuExample testdanmuExample=new TestdanmuExample();
		testdanmuExample.setPage(page);
		Criteria criteria =testdanmuExample.or();
		if(testdanmu.getUserid()!=null){
			criteria.andUseridEqualTo(testdanmu.getUserid());
		}
		if(testdanmu.getVideoid()!=null){
			criteria.andVideoidEqualTo(testdanmu.getVideoid());
		}
		return testdanmuMapper.selectByExample(testdanmuExample);
	}
	@Override
	public int deleteDanmu(int id) {
		TestdanmuExample testdanmuExample=new TestdanmuExample();
		if(id+""!=null){
			testdanmuExample.or().andDanmuidEqualTo(id);
			return testdanmuMapper.deleteByPrimaryKey(id);
		}else{
			return 0;
		}
	}
	@Override
	public int getPageNum() {
		TestdanmuExample testdanmuExample=new TestdanmuExample();
		return testdanmuMapper.countByExample(testdanmuExample);
	}
}